package com.sinog.front.util;

import com.sinog.front.config.ProvinceCodesConfig;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @desc 加载配置文件，获取省份url
 * @author lzq
 * @date -
 */
@Configuration
@Log4j2
public class CodeUrlUtils {

    private static final Map<String,String> MAPS = new HashMap<>(16);
    /**
     * 1、注入实例ProvinceCodesConfig并赋值ProvinceCodesConfig
     */
    private ProvinceCodesConfig provinceCodesConfig;

    /**
     * 描述
     * @param provinceCodesConfig provinceCodesConfig
     */
    @Autowired
    public void setProvinceCodesConfig(ProvinceCodesConfig provinceCodesConfig) {
        this.provinceCodesConfig = provinceCodesConfig;
        List<Map<String,String>> valueMapList = this.provinceCodesConfig.getValueMapList();
        for(Map<String,String> m : valueMapList) {
            MAPS.putAll(m);
        }
    }

    /**
     * 获取当前系统省份code
     * @return String
     */
    public static String getLocalCode() {
        return String.valueOf(MAPS.get("local-code"));
    }
}